package ui.uea;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

public class FrameworkTableModel extends AbstractTableModel {
private static final long serialVersionUID = 1L;
	public static final String BLANK = "";
		private String[] columnNames ;
	    private List<Object[]> data;
		public FrameworkTableModel(String[] columnNames, Object[][] data) {
			super();
			this.columnNames = columnNames;
			this.data = new LinkedList<Object[]>(Arrays.asList(data));
		}
		public void setRowCount(int r){
			int idx = data.size();
			for(int i = idx - 1; i >= r; i--){
				data.remove(i);
			}
		}
		public void addRow(Object[] row){
			data.add(row);
		}
		public int getColumnCount() {  
	        return columnNames.length;  
	    }  
	  
	    public int getRowCount() {  
	        return data.size();  
	    }  
	  
	    public String getColumnName(int col) {  
	        return columnNames[col].toString();  
	    }  
	  
	    public Object getValueAt(int row, int col) {  
	        return data.get(row)[col];  
	    } 
public Class<?> getColumnClass(int c) {  
    return getValueAt(0, c).getClass();  
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
	if(columnIndex == 0 || columnIndex == 4 || this.getValueAt(rowIndex, columnIndex) == BLANK){
		return false;
	}
    return true;
}
public void setValueAt(Object value, int row, int col) {
    data.get(row)[col] = value;
    fireTableCellUpdated(row, col);
}
}
